package com.stars.pao.junit01;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

public class OccupantTest {
    @Test
    public void noStartSquare() {

        Unit unit = new Unit();
        assertNull(unit.getTargetSquare(), "Unit 在未调用 occupy 方法时不应有目标方格");
    }

    @Test
    public void testOccupy() {
        Unit unit = new Unit();
        Square square = new Square();
        unit.occupy(square);
        assertEquals(square, unit.getTargetSquare(), "Unit 占据 Square 后，目标方格应与指定的 Square 一致");
        assertTrue(square.contains(unit), "Square 应包含占据它的 Unit");
    }


    @Test
    public void testReoccupy() {
        Unit unit = new Unit();
        Square square1 = new Square();
        Square square2 = new Square();
        unit.occupy(square1);
        unit.occupy(square2);
        assertEquals(square2, unit.getTargetSquare(), "Unit 重复占据后，目标方格应是最后占据的 Square");
        assertFalse(square1.contains(unit), "第一个 Square 不应再包含 Unit");
        assertTrue(square2.contains(unit), "第二个 Square 应包含占据它的 Unit");
    }
}
